package com.lwj.file.controller;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.lwj.file.entity.OrderDTO;
import com.lwj.file.listener.DemoDataListener;
import com.lwj.file.service.impl.OrderServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;

/**
 * @ClassName:FileController
 * @Description:
 * @Author:lwj
 * @Date:2020/6/15 22:42
 **/
@RestController
public class FileController {

    @Resource
    private OrderServiceImpl orderService;
    @Resource
    private DemoDataListener demoDataListener;



    @GetMapping(value = "/export")
    public  void export(HttpServletResponse response,Integer pageSize,Integer limit) throws IOException {
        orderService.export(response, pageSize, limit);
    }

    @PostMapping(value = "/upload")
    public  void upload(MultipartFile file){
        //传入自定义线程池
        CompletableFuture.runAsync(()->{
            BufferedInputStream inputStream = FileUtil.getInputStream("/Users/luweijie/Documents/github/MultithreadedExportExcelData/sql/11111.xlsx");
            EasyExcelFactory.read(inputStream, OrderDTO.class, demoDataListener).excelType(ExcelTypeEnum.XLSX).sheet().doRead();
        });

    }



}
